﻿using System;

namespace Optional
{
    public class Option
    {
        private Option() { }

        public static Option<T> Some<T>(T value) => new Option<T>(value);

        public static Option None => null!;

        public static Option<T> Try<T>(Func<T> tryGetSome)
        {
            try
            {
                return new Option<T>(tryGetSome());
            }
            catch
            {
                return None;
            }
        }
    }
}
